package com.thread.threadfirst.studyThread2;

import java.util.concurrent.TimeUnit;

public class T6 {

    volatile static Person p = new Person();     //这里一定要加volatile才能保证每次输出都是suolong，而不加可能是lufei也可能是suolong

    public static void main(String[] args) {
        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(p.name);
        }).start();

        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            p.name = "suolong";
        }).start();
    }

}

class Person {
    String name = "lufei";
}